package com.lm.sm.example;


import org.bouncycastle.crypto.digests.SM3Digest;
import org.bouncycastle.util.encoders.Hex;

public class SM3Example {
    public static String sm3Hash(String input) {
        SM3Digest digest = new SM3Digest();
        byte[] inputBytes = input.getBytes();
        digest.update(inputBytes, 0, inputBytes.length);
        byte[] hash = new byte[digest.getDigestSize()];
        digest.doFinal(hash, 0);
        return Hex.toHexString(hash);
    }

    public static void main(String[] args) {
        String data = "国密SM3测试";
        String hash = sm3Hash(data);
        System.out.println("SM3 Hash: " + hash);
    }
}
